// 获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: null,
    hasUserInfo: false,
  },
  onLoad() {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const _user = wx.getStorageSync(app.cache.AUTH_USER);
    if (_user) {
      this.setData({ hasUserInfo: true, userInfo: _user })
    }else{
      this.setData({ hasUserInfo: false, userInfo: null })
    }
  },

  getUserProfile(e) {
    app.getOpenId();
  },

  clearCache: function () {
    var self = this;
    wx.showModal({
      title: "确认清空缓存",
      content: "会删除所有本地数据！",
      success: function success(res) {
        if (res.confirm) {
          try {
            wx.clearStorageSync();

            app.getOpenId();//清除之后重新获取openId,不然登录页面获取不到openId
          } catch (e) {
            wx.showToast({
              title: "清空失败！"
            });
          }
        }
      }
    });
  }
})
